package com.xinshujia.controller;

import com.xinshujia.entity.ThresholdEntity;
import com.xinshujia.response.RespResult;
import com.xinshujia.service.FunctionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-08-07 09:27       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 */
@RestController
@RequestMapping("function")
public class FunctionController {
    private final FunctionService functionService;

    public FunctionController(FunctionService functionService) {
        this.functionService = functionService;
    }

    /**
     * 采集
     * @param deviceGuid 设备ID
     * @param operateType 0：关闭，1：开启
     */
    public RespResult collectOperate(String deviceGuid, Integer operateType) {
        boolean flag = functionService.collectOperate(deviceGuid, operateType);
        return flag ? RespResult.OK() : RespResult.Fail();
    }


    /**
     * 报警
     * @param deviceGuid 设备ID
     * @param operateType 0：关闭，1：开启，2：清除
     */
    public RespResult alarmOperate(String deviceGuid, Integer operateType) {
        boolean flag = functionService.alarmOperate(deviceGuid, operateType);
        return flag ? RespResult.OK() : RespResult.Fail();
    }

    /**
     * 设置或更新阈值
     */
    public RespResult setOrUpdateThreshold(ThresholdEntity thresholdEntity) {
        boolean flag = functionService.updateThreshold(thresholdEntity);
        return flag ? RespResult.OK() : RespResult.Fail();
    }
}
